﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Messhall.Framework.Converts
{
    public class Mapping
    {
        /// <summary>
        /// 实体转换
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T1"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T Convert<T, T1>(T1 model)
        {
            var modelJsonString = JsonConvert.SerializeObject(model);
            return JsonConvert.DeserializeObject<T>(modelJsonString);
        }

        /// <summary>
        /// 实体转换
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T Convert<T>(object model)
        {
            var modelJsonString = JsonConvert.SerializeObject(model);
            return JsonConvert.DeserializeObject<T>(modelJsonString);
        }
    }
}